#!/bin/bash

# LFS-Automatic - An Automated Linux From Scratch-Installer
# Copyright (C) 2009 - 2011  Team Developer Dertin GNU/Linux
#
#
# LFS-Automatic comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
# This is free software, and you are welcome to redistribute it
# under certain conditions; see COPYING for details.

# Amended by: Guillermo Céspedes Tabárez
# 13/01/2009


function Adjusting ()
{
	# 5.8. Adjusting the Toolchain
	
	mv -v /tools/bin/{ld,ld-old}
	mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
	mv -v /tools/bin/{ld-new,ld}
	ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld
		
	gcc -dumpspecs | sed 's@/lib/ld-linux.so.2@/tools&@g' \
  	> `dirname $(gcc -print-libgcc-file-name)`/specs
	
	GCC_FIXED=`dirname $(gcc -print-libgcc-file-name)`/include-fixed &&
	find ${GCC_FIXED}/* -maxdepth 0 -xtype d -exec rm -rvf '{}' \; &&
	rm -vf `grep -l "DO NOT EDIT THIS FILE" ${GCC_FIXED}/*` &&
	unset GCC_FIXED
	
	echo 'main(){}' > dummy.c
	cc dummy.c
	readelf -l a.out | grep ': /tools'
	if [ $? = 1 ]; then
	echo "Error Adjusting the Toolchain"
	rm -v dummy.c a.out
	exit 1
	fi
	
	rm -v dummy.c a.out
	# End commands
}

Adjusting
